<?php
declare (strict_types=1);

namespace app\api\controller;

use app\api\BaseController;
use app\api\service\UserService;
use app\system\service\DeviceService;
use app\traits\UserTrait;
use think\helper\Arr;

class Device extends BaseController
{
    use UserTrait;

    private DeviceService $service;

    public function initialize()
    {
        $this->service = new DeviceService();
        parent::initialize();
    }

    /**
     * 设备类型列表
     *
     * @return \think\Response
     */
    public function types(): \think\Response
    {
        return $this->success($this->service->types());
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        return $this->success($this->service->getList($this->request->get()));
    }

    public function update($id)
    {
        $putData = $this->request->all();
        $putData['source'] = 'api';
        [$isOk, $result] = $this->service->update($id, $putData);
        return $isOk ? $this->success($result) : $this->error($result);
    }

    public function batchUpdateStatus()
    {
        $data = $this->request->post();
        $data['source'] = 'api';
        [$isOk, $result] = $this->service->batchUpdateStatus($data);
        return $isOk ? $this->success($result) : $this->error($result);
    }

}
